package com.cssw.fyzb.tps.api.wx;

import com.alibaba.fastjson.JSON;
import com.cssw.fyzb.tps.model.vo.WxOperIdVo;
import com.cssw.fyzb.tps.util.HttpUtil;
import com.cssw.fyzb.tps.util.MapUtil;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author: yangyiqun
 * @Date: 2021/1/7 15:26
 */
@Function(description = "获取微信小程序openId", parameters = {
        @Parameter(name = "code", type = Type.String, description = "微信code", required = true)
})
@Component
public class GetWxOpenId implements Action {

    @Value("${wx.auth.code2Session}")
    private String code2Session;

    @Override
    public Response execute(Request request) throws Exception {
        String code = request.getString("code");
        String result = HttpUtil.get(code2Session + code);
        WxOperIdVo vo = new WxOperIdVo();
        Map map = JSON.parseObject(result, Map.class);
//        vo.setOperId(MapUtil.getString(map, "operId"));
        return Response.success().put("data", map);
    }
}
